<?php

namespace app\admin\controller\post;

use app\common\controller\Backend;

class Post extends Backend
{
    //构造函数
    public function __construct()
    {
        parent::__construct();

        //全局
        $this->PostModel = model('Post.Post');
        //分类
        $this->CateModel = model('Post.Cate');
    }
    public function index()
    {
        $title = '分类列表';
        $keywords = $this->request->param('keywords', '');
        $start = $this->request->param('start', '');
        $end = $this->request->param('end', '');

        $where = [];

        //关键字
        if(!empty($keywords)){

            $where['title'] = ['like',"%$keywords%"];

        }

        //判断开始时间是否为空
        if(!empty($start))
        {
            //标准时间转化为时间戳
            $starttime = strtotime($start);
            $where['createtime'] = ['EGT', $starttime];
        }

        if(!empty($end))
        {
            //标准时间转化为时间戳
            $endtime = strtotime($end);
            $where['createtime'] = ['ELT', $endtime];
        }

        //总数
        $count = $this->PostModel->count();
      
        $postlist = $this->PostModel->with(['cate', 'user'])->where($where)->order('createtime','desc')->paginate(10);

        $pagestr = $postlist-> render();

        //赋值
        $this->assign([
            'title' => $title,
            'count' =>  $count,
            'postlist' => $postlist,
            'pagestr' => $pagestr,
            'keywords' => '',
            'start' => '',
            'end' => '',
        ]);
        return $this->fetch();
    }
  

   
   
}
